#include "queue_stack.h"
/*
int my_push_stack(queue_t *A,queue_t *B,int num){
    if(NULL == A || NULL == B){
        return -1;
    }
    if(is_empty(A)){
       push_queue(A,num);
       int temp = 0;
       while(!is_empty(B)){
        if(!pop_queue(B,&temp)){
            push_queue(A,temp);
        }
       }
    }else{
        int temp = 0;
        while (!is_empty(A)) {
            push_queue(B,num);
            if (!pop_queue(A, &temp)) {
               push_queue(B,temp);
            }
        }
    }  
    return 0;  
}

int my_pop_stack(queue_t *A,queue_t *B,int *buff){
    if(NULL == A || NULL == B || NULL == buff){
        return -1;
    }
    if (!is_empty(A)) {
        return pop_queue(A, buff);
    } else {
        if (!is_empty(B)) {
            return pop_queue(B, buff);
        } else {
            return -1;
        }
    }
}
*/
// 入栈
int my_push_stack(queue_t *A, queue_t *B, int num){
    if(NULL == A || NULL == B){
        return -1;
    }
    int temp = 0;
    if(is_empty(A)){
        push_queue(A, num);
        while(!pop_queue(B, &temp)){
            push_queue(A, temp);
        }
    }else{
        push_queue(B, num);
        while(!pop_queue(A, &temp)){
            push_queue(B, temp);
        }
    }
    return 0;
}

// 出栈
int my_pop_stack(queue_t *A, queue_t *B, int *buff){
    if(NULL == A || NULL == B || NULL == buff){
        return -1;
    }
    if(is_empty(A)){
        if(is_empty(B)){
            return -1;
        }else{
            pop_queue(B, buff);
        }
    }else{
        pop_queue(A, buff);
    }
    return 0;
}
int main(int argc, char const *argv[])
{
   queue_t *A = NULL;
   create_queue(&A);
   queue_t *B = NULL;
   create_queue(&B);

   my_push_stack(A,B,10);
   my_push_stack(A,B,20);
   my_push_stack(A,B,30);

   int value = 0;
   my_pop_stack(A, B, &value);
   printf("value = %d\n", value); //30
   my_pop_stack(A, B, &value);
   printf("value = %d\n", value); //20
   my_pop_stack(A, B, &value);
   printf("value = %d\n", value);//10
   

    return 0;
}
